package org.jeecg.common.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.modules.sys.entity.SysAccountFlow;
import org.jeecg.common.modules.sys.mapper.SysAccountFlowMapper;
import org.jeecg.common.modules.sys.service.ISysAccountFlowService;
import org.jeecg.common.util.enums.SysAccountFlowTypeEnum;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @author guoyh
 * @ClassName SysAccountServiceImpl
 * @Description
 * @since 2020/9/5 16:08
 **/
@Service
public class SysAccountFlowServiceImpl extends ServiceImpl<SysAccountFlowMapper, SysAccountFlow> implements ISysAccountFlowService {

    @Override
    public void addAccountFlow(Long sysAccountId, SysAccountFlowTypeEnum flowType, BigDecimal amount,String relationId,String createUser){
        SysAccountFlow flow = new SysAccountFlow();
        flow.setSysAccountId(sysAccountId);
        flow.setAmount(amount);
        flow.setType(SysAccountFlowTypeEnum.DOCTOR_SERVICE.getCode());
        flow.setCreateTime(new Date());
        flow.setRelationId(relationId);
        flow.setCreateUser(createUser);
        save(flow);
    }

    @Override
    public SysAccountFlow getSysAccountFlow(Long sysAccountId, SysAccountFlowTypeEnum flowType, String relationId) {
        LambdaQueryWrapper<SysAccountFlow> query = Wrappers.lambdaQuery();
        query.eq(SysAccountFlow::getSysAccountId,sysAccountId);
        query.eq(SysAccountFlow::getType,flowType.getCode());
        query.eq(SysAccountFlow::getRelationId,relationId);
        return getOne(query);
    }


}
